package com.hndfsj.framework.controller.base;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.math.NumberUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.hndfsj.framework.config.RWAdminConfiguration;
import com.hndfsj.framework.pager.PageRequest;

/**
 * Common
 * @copyright {@link www.hndfsjsoft.com}
 * @version 2013-1-15 上午09:53:44
 * @see com.hndfsj.framework.controller.base.BaseCommonRestJSONController
 * 
 * @param <Entity>
 * @param <PK>
 */
public class BaseCommonRestJSONController {


	/**
	 * 在方法调用前执行,可以存放一些共享变量,如枚举值,或是一些初始化操作
	 * 
	 * @param model
	 * @author Mr.Hao
	 * @version 2013-1-15 上午09:56:20
	 */
	@ModelAttribute("")
	public void init(Model model) {
		model.addAttribute("now", new java.sql.Timestamp(System.currentTimeMillis()));
	}

	/**
	 * 提取前台分页信息
	 * 
	 * @param request
	 * @return
	 * @author Mr.Hao
	 * @version 2013-1-15 上午10:00:01
	 */
	protected PageRequest newPageRequest(HttpServletRequest request) {
		int pageIndex = NumberUtils.toInt(request.getParameter("pageIndex"), 1);
		int pageSize = NumberUtils.toInt(request.getParameter("pageSize"), Integer
				.parseInt(RWAdminConfiguration.getInstance().getAppPropsValue("pagesize", "15")));

		String sortCol = request.getParameter("sortCol");
		String sortOrder = request.getParameter("sortOrder");
		return new PageRequest(pageIndex, pageSize, sortCol, sortOrder);
	}



	
}
